home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sun4c / archive / tcltk.z / tcltk / slib / tk / demos / timer < prev    next >
Text File  |  1994-09-20  |  884b  |  36 lines

  1. #!///////////////////////////////////////////////////////////////////////////usr/STAGE/bin/wish -f
  2. #
  3. # This script generates a counter with start and stop buttons.
  4.  
  5. label .counter -text 0.00 -relief raised -width 10
  6. button .start -text Start -command {
  7.     if $stopped {
  8.     set stopped 0
  9.     tick
  10.     }
  11. }
  12. button .stop -text Stop -command {set stopped 1}
  13. pack .counter -side bottom -fill both
  14. pack .start -side left -fill both -expand yes
  15. pack .stop -side right -fill both -expand yes
  16.  
  17. set seconds 0
  18. set hundredths 0
  19. set stopped 1
  20.  
  21. proc tick {} {
  22.     global seconds hundredths stopped
  23.     if $stopped return
  24.     after 50 tick
  25.     set hundredths [expr $hundredths+5]
  26.     if {$hundredths >= 100} {
  27.     set hundredths 0
  28.     set seconds [expr $seconds+1]
  29.     }
  30.     .counter config -text [format "%d.%02d" $seconds $hundredths]
  31. }
  32.  
  33. bind . <Control-c> {destroy .}
  34. bind . <Control-q> {destroy .}
  35. focus .
  36.